package com.have.blog.admin.controller;


import com.have.blog.utils.ResultUtils;
import com.have.blog.xo.constant.SysConstant;
import com.have.blog.xo.service.admin.AdminBlogService;
import com.have.blog.xo.service.admin.AdminIndexService;
import com.have.blog.xo.service.admin.AdminWebVisitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(value = "首页相关接口", tags = {"首页相关接口"})
@RequestMapping("/index")
@Slf4j
public class AdminIndexController {

    @Autowired
    private AdminIndexService adminIndexService;
    @Autowired
    private AdminWebVisitService webVisitService;
    @Autowired
    private AdminBlogService blogService;

    @ApiOperation(value = "首页初始化数据", notes = "首页初始化数据", response = String.class)
    @RequestMapping(value = "/init", method = RequestMethod.GET)
    public String init() {
        return ResultUtils.result(SysConstant.SUCCESS, adminIndexService.init());
    }

    @ApiOperation(value = "获取最近一周用户独立IP数和访问量", notes = "获取最近一周用户独立IP数和访问量", response = String.class)
    @RequestMapping(value = "/getVisitByWeek", method = RequestMethod.GET)
    public String getVisitByWeek() {
        return webVisitService.getVisitByWeek();
    }

    @ApiOperation(value = "获取每个标签下文章数目", notes = "获取每个标签下文章数目", response = String.class)
    @RequestMapping(value = "/getBlogCountByTag", method = RequestMethod.GET)
    public String getBlogCountByTag() {
        return blogService.getBlogCountByTag();
    }

    @ApiOperation(value = "获取每个分类下文章数目", notes = "获取每个分类下文章数目", response = String.class)
    @RequestMapping(value = "/getBlogCountByCategory", method = RequestMethod.GET)
    public String getBlogCountByCategory(){
        return blogService.getBlogCountByCategory();
    }

    @ApiOperation(value = "获取一年内的文章贡献数", notes = "获取一年内的文章贡献度", response = String.class)
    @RequestMapping(value = "/getBlogContributeCount", method = RequestMethod.GET)
    public String getBlogContributeCount() {
        return blogService.getBlogContributeCount();
    }
}
